﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SoccerEvaluator.Common;
using System.IO;
using SoccerEvaluator.Business;
using SoccerEvaluator.WebSite.App_Code;

namespace SoccerEvaluator.WebSite
{
    /// <summary>
    /// 
    /// </summary>
    public partial class MatchUsers : System.Web.UI.Page
    {
        /// <summary>
        ///
        /// </summary>
        protected int _groupID
        {
            get
            {
                if (Session["GroupId"] != null)
                {
                    return int.Parse(Session["GroupId"].ToString());
                }
                else return 0;
            }
        }
        /// <summary>
        ///
        /// </summary>
        protected int _projectID
        {
            get
            {
                if (Request.QueryString["ID"] != null)
                {
                    return int.Parse(Request.QueryString["ID"]);
                }
                else return 0;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        protected string _projectName;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {

                SoccerEvaluatorModelContainer context = new SoccerEvaluatorModelContainer();

                TemplateInfo projectInfo = ObjectFactory.ToTemplateInfo(context.Templates.FirstOrDefault(c => c.Id == _projectID));

                _projectName = projectInfo.Name;

                this.lblCatchScore.Text = projectInfo.CatchScore.ToString();
                this.lblExactScore.Text = projectInfo.ExactScore.ToString();

                int totalUsers = context.UserScores.Count(c => c.TemplateId == _projectID);

                this.lblTotalUsers.Text = totalUsers.ToString();

            }

        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="list"></param>
        /// <param name="dateTime"></param>
        /// <returns></returns>
        private int GetIndexFromDate(List<TemplateScoreInfo> list, DateTime date)
        {
            //Por defecto el mas grande de la lista esperado
            int index = 0;

            for (int i = 0; i < list.Count; i++)
            {
                TemplateScoreInfo s = list[i];

                TimeSpan ts = s.Date - date;

                if (ts.TotalDays < 1)
                {
                    index = i + 1;
                }
            }

            return index;
        }


    }
}